/* GUI CONVERTED from ecpsfm04.p (converter v1.75) Mon Aug 14 12:27:56 2000 */
/* ecpsfm04.p - BOM SUMMARY SUB-ROUTINE: Create psmstr from ECN database */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                   */
/* All rights reserved worldwide.  This is an unpublished work.          */
/* web convert ecpsfm04.p (converter v1.00) Mon Oct 06 14:21:50 1997 */
/* web tag in ecpsfm04.p (converter v1.00) Mon Oct 06 14:18:05 1997 */
/*K0M7*/ /*V8#ConvertMode=WebReport                            */
/*V8:ConvertMode=Report                                                  */
/* REVISION: 7.4       LAST EDIT: 04/20/95      MODIFIED BY: QZL *H0DB*  */
/* REVISION: 8.6       LAST EDIT: 10/08/97      MODIFIED BY: mzv *K0M7*  */
/* REVISION: 8.6       LAST EDIT: 05/29/98      MODIFIED BY: *K1R6* A.Shobha  */
/* REVISION: 8.6   LAST MODIFIED: 01/28/99      BY: *K1Z2* Santhosh Nair */
/* REVISION: 9.1   LAST MODIFIED: 08/14/00      BY: *N0KW* Jacolyn Neder      */
     /* THIS SUBROUTINE CREATES PRODUCT STRUCTURE WORK FILES FOR      */
     /* 'THIS ECN' AS WELL AS 'PREVIOUS RELEASED ECNS'. THERE ARE     */
     /* SOME DATE MANIPULATIONS ON STRUCTURE START AND END DATES:     */
     /*      LIVE STRUCTURE: START = TODAY; END = TODAY + 750         */
     /* PRE REL ECN STRUCTURE: START = TODAY + 751; END = TODAY + 751 */
     /*  THIS ECN STRUCTURE: START = TODAY + 1501; END = TODAY + 1501 */


/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

     {mfdeclre.i}
/*K1R6 /*K0M7*/ {wbrp02.i} */


     define input parameter ecd1_no as recid.
     define input parameter ecmnbr like ecm_nbr.
/*K1Z2** BEGIN DELETE **
 *   define shared workfile psmstr like ps_mstr.
 *   define shared variable wkfl_no as integer.
 *   define shared variable maxwkfl as integer.
 *K1Z2** END DELETE */
/*K1Z2*/ define shared temp-table psmstr like ps_mstr.
     define variable psmstr_no as recid no-undo.
     define variable temp_ref like ps_mstr.ps_ref no-undo.

     define buffer ecd1 for ecd1_det.
     define buffer ecm  for ecm_mstr.

     find ecd1_det where recid(ecd1_det) = ecd1_no no-lock no-error.
     if available ecd1_det then do:

        find first psmstr no-lock where
        psmstr.ps_par       = ecd1_det.ecd1_par and
        psmstr.ps_comp      = ecd1_det.ecd1_comp and
        psmstr.ps_ref       = ecd1_det.ecd1_ref  and
        psmstr.ps_start     = today no-error.
        if available psmstr then psmstr_no = recid(psmstr).
        else psmstr_no = ?.

        temp_ref = ?.
        find first psmstr no-lock where
        psmstr.ps_par       = ecd1_det.ecd1_par and
        psmstr.ps_comp      = ecd1_det.ecd1_comp and
        psmstr.ps_ref       = ecd1_det.ecd1_ref  and
        psmstr.ps_start     = today + 1501 and
        psmstr.ps_end       = today + 1501 no-error.
        if not available psmstr and not ecd1__qad01 then do:
           create psmstr.
           assign psmstr.ps_par = ecd1_det.ecd1_par
              psmstr.ps_comp = ecd1_det.ecd1_comp
              psmstr.ps_ref = ecd1_det.ecd1_ref
              psmstr.ps_start = today + 1501
              psmstr.ps_end = today + 1501
              psmstr.ps_qty_per_b = ecd1_det.ecd1_qty_per_b
              psmstr.ps_qty_per = ecd1_det.ecd1_qty_per
              psmstr.ps_ps_code = ecd1_det.ecd1__qad03
              psmstr.ps_scrp_pct = ecd1_det.ecd1_scrp_pct.
           if recid(psmstr) <> -1 then.
           temp_ref = ecd1_det.ecd1_ref.
/*K1Z2 BEGIN DELETE  **
 *          wkfl_no = wkfl_no + 1.
 *          if wkfl_no > maxwkfl then do:
 *         {mfmsg.i 5671 2}
 *         return.
 *          end.
 *K1Z2 END DELETE   */
        end.

        if psmstr_no <> ? then do:
           find psmstr exclusive-lock where recid(psmstr) = psmstr_no no-error.
           if available psmstr then psmstr.ps_end = today + 1500.
        end.

        for each ecm where ecm.ecm_rel_date <> ? and ecm.ecm_nbr <> ecmnbr
           and ecm.ecm_eff_date = ? and  ecm.ecm_close_date = ?
           no-lock use-index ecm_approval,
        each ecd1 where ecd1.ecd1_nbr  = ecm.ecm_nbr and
           ecd1.ecd1_par  = ecd1_det.ecd1_par and ecd1.ecd1_comp =
           ecd1_det.ecd1_comp no-lock
        break by ecd1.ecd1_par by ecd1.ecd1_comp by ecd1.ecd1_ref by
        ecm.ecm_rel_date descending:
           if first-of(ecm.ecm_rel_date) then do:
          if not ecd1.ecd1__qad01 then do:
             find first psmstr no-lock where
            psmstr.ps_par       = ecd1.ecd1_par and
            psmstr.ps_comp      = ecd1.ecd1_comp and
            psmstr.ps_ref       = ecd1.ecd1_ref  and
            psmstr.ps_start     = today + 751 no-error.
             if not available psmstr then do:
            create psmstr.
            assign psmstr.ps_par = ecd1.ecd1_par
                   psmstr.ps_comp = ecd1.ecd1_comp
                   psmstr.ps_ref = ecd1.ecd1_ref
                   psmstr.ps_start = today + 751
                   psmstr.ps_end = if temp_ref <> ? and temp_ref
                           <> ecd1.ecd1_ref then today +
                           1501 else today + 751
                   psmstr.ps_qty_per_b = ecd1.ecd1_qty_per_b
                   psmstr.ps_qty_per = ecd1.ecd1_qty_per
                   psmstr.ps_ps_code = ecd1.ecd1__qad03
                   psmstr.ps_scrp_pct = ecd1.ecd1_scrp_pct.
            if recid(psmstr) <> -1 then.
/*K1Z2** BEGIN DELETE   **
 *           wkfl_no = wkfl_no + 1.
 *           if wkfl_no > maxwkfl then do:
 *              {mfmsg.i 5671 2}
 *              return.
 *           end.
 *K1Z2** END  DELETE  */
             end.
          end.
          if psmstr_no <> ? then do:
             find psmstr exclusive-lock where recid(psmstr) = psmstr_no
             no-error.
             if available psmstr and psmstr.ps_ref = ecd1.ecd1_ref
             then psmstr.ps_end = today + 750.
          end.
           end.
        end.
     end.
/*K1R6 /*K0M7*/ {wbrp04.i} */
